#ifndef CRENDER_H_
#define CRENDER_H_

#include <Windows.h>
#include <D3D10_1.h>
#include <D3DX10.h>
#include <d3dx10math.h>
#include <D2D1.h>
#include <d2d1helper.h>
#include <dwrite.h>
#include <D3Dcompiler.h>
#include <wincodec.h>
#include <xnamath.h>
#include <vector>
#include "Utility.h"

#pragma comment(lib, "d3d10.lib")
#pragma comment(lib, "d3dx10.lib")
#pragma comment (lib, "Windowscodecs.lib")


//very simple vertex for testing
struct SimpleVertex
{
	D3DXVECTOR3 Pos;
	D3DXVECTOR4 Color;
};


struct SimpleBuffer
{
	ID3D10InputLayout* m_pVertexLayout;
	ID3D10Buffer* m_pVertexBuffer;
	ID3D10Buffer* m_pIndexBuffer;
};


struct SSprite
{
	D3DX10_SPRITE* m_pSprite;
	int m_Width;
	int m_Height;
};


class CRender
{
	CRender();
	~CRender();
	CRender(const CRender&);
	CRender& operator=(const CRender&);

	D3D10_DRIVER_TYPE m_DriverType;
	//D3D_FEATURE_LEVEL m_FeatureLevel;

	ID3D10Device* m_pD3DDevice;
	IDXGISwapChain* m_pSwapChain;
	ID3D10RenderTargetView* m_pRenderTargetView;
	ID3D10Effect* m_pEffect;
	ID3D10EffectTechnique* m_pTechnique;


	//2D shit
	ID2D1Factory* m_pD2DFactory;
	IWICImagingFactory *m_pWICFactory;
	IDWriteFactory *m_pDWriteFactory;
	ID2D1RenderTarget *m_pBackBufferRT;

	D3DX10_SPRITE* srcTexture;
	ID3DX10Sprite* m_pSpriteManager;

	ID3D10BlendState* pOriginalBlendState10;
	ID3D10BlendState* pBlendState10;



	// Device-Independent Resources
	IDWriteTextFormat *m_pTextFormat;
	ID2D1PathGeometry *m_pPathGeometry;


	//will prob want to change these to arrays / vectors
	std::vector<ID3D10VertexShader*> m_pVertexShaders;
	std::vector<ID3D10PixelShader*> m_pPixelShaders;

	std::vector<SimpleBuffer> m_pSimpleBuffers;



public:

	//should be in a camera class, just sayin
	D3DXMATRIX g_World;
	//D3DXMATRIX g_View;
	//D3DXMATRIX g_Projection;
	ID3D10EffectMatrixVariable* g_pWorldVariable;
	ID3D10EffectMatrixVariable* g_pViewVariable;
	ID3D10EffectMatrixVariable* g_pProjectionVariable;

	D3DXMATRIX g_2DProjection;

	static CRender* GetInstance();

	bool InitDevice(HWND hWnd);
	//bool InitNoneDevice(HWND hWnd);
	bool Shutdown();

	void ClearBackBuffer();
	void PresentBackBuffer();

	void Render();
	void Render2D();

	//take this shit out
	void Render2D(D3DX10_SPRITE* texture);

	HRESULT CompileShaderFromFile(char* szFileName, LPCSTR szEntryPoint, LPCSTR szShaderModel, ID3DBlob** ppBlobOut);

	SSprite* LoadTexture2DFromFile(std::string fileName);
	void GetResourceViewFromTexture(ID3D10Texture2D* texture, ID3D10ShaderResourceView **resourceView);

	ID3D10Device* GetD3DDevice(){ return m_pD3DDevice; }
};

#endif